package com.akhan.jplearn.mapper;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ClassPathResource;
import com.google.common.collect.Lists;

import java.io.InputStream;
import java.util.List;

/**
 * 五十音对照
 *
 * @author YuKang
 * @date 2021/6/24 23:32
 */
public class JPWordMapper {
    private static List<String> hiragana = Lists.newArrayList();
    private static List<String> katakana = Lists.newArrayList();
    private static List<String> gojyuuon = Lists.newArrayList();

    static {
        ClassPathResource resource = new ClassPathResource("HojuuonTable");
        InputStream is = resource.getStream();
        IoUtil.readLines(is, "utf-8", Lists.newArrayList()).forEach(n -> {
            hiragana.add(n.substring(0, 1));
            katakana.add(n.substring(1, 2));
            gojyuuon.add(n.substring(2));
        });
    }

    public static int indexOf(String in){
        int i = hiragana.indexOf(in);
        if (i >= 0){
            return i;
        }
        i = katakana.indexOf(in);
        if (i >= 0){
            return i;
        }
        i = gojyuuon.indexOf(in);
        if (i >= 0){
            return i;
        }

        return i;
    }

    public static int size(){
        return hiragana.size();
    }

    public static String getHiragana(int idx){
        return hiragana.get(idx);
    }

    public static String getKatakana(int idx){
        return katakana.get(idx);
    }

    public static String getGojyuuon(int idx){
        return gojyuuon.get(idx);
    }
}
